home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / KEYIO1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.4 KB  |  49 lines

  1. /*  keyio1.c - getkey() and keypress() functions */
  2. /*  system dependant part of the keyboard input module */
  3. /*  this version uses BIOS function calls */
  4. #include   "stdio.h"
  5. #include   "cminor.h"
  6. #include   "asmtools.h"
  7. #include   "dosfun.h"
  8. #include   "keyio.h"
  9.  
  10.   /* constants for BIOS calls */
  11. #define    KEYIO_CALL    0x16    /* software interrupt number */
  12. #define    CHK_STAT    0x0100    /* function code for check input status */
  13. #define    GET_CHR    0x0000    /* function code for getting a char */
  14.  
  15. int  keypress()         /* check for keyboard input waiting */
  16.   {
  17.      int   stat ;
  18.      REGS  sreg , dreg ;
  19.  
  20.      sreg.ax = CHK_STAT ;    /* do BIOS call to check status */
  21.      stat = swint(KEYIO_CALL,&sreg,&dreg) & ZF_FLAG ;
  22.  
  23.      if( stat == 0 )
  24.        return( 1 ) ;    /* input is waiting */
  25.     else  return( 0 ) ;    /* no input waiting */
  26.   }
  27.  
  28.  
  29. /* getkey - waits for and returns the next keystroke input */
  30. /* keystrokes that the ROM-BIOS describes with extended codes */
  31. /* are returned as integers > 255 */
  32.  
  33. int getkey()            /* get the next key input */
  34.   {
  35.      int   c ;
  36.      REGS  sreg , dreg ;
  37.  
  38.      sreg.ax = GET_CHR ;
  39.      swint(KEYIO_CALL,&sreg,&dreg) ;
  40.      c = dreg.ax & 0xff ;    /* get ASCII code */
  41.      if( c == 0 )        /* is it a non-ASCII extended code */
  42.     c = 0x100 + (dreg.ax >> 8) ;    /* yes - use 256 + scan code */
  43.      return( c ) ;
  44.   }
  45.  
  46.  
  47.  
  48.  
  49.